// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Web.Core;

public class FilterContextInfo
{
    public FilterContextInfo(ActionExecutingContext filterContext)
    {
        #region 获取链接中的字符

        //try
        //{
        //    if (filterContext.HttpContext.User.Claims.Any(o => o.Type == ClaimConst.Claim_UserId))
        //    {
        //        var sid = filterContext.HttpContext.User.FindFirst(ClaimConst.Claim_UserId).Value;
        //        this.UserId = sid.To<int>();
        //    }
        //}
        //catch (System.Exception ex)
        //{
        //}

        UserId = filterContext.HttpContext.GetLoginUserId<int>();

        // 获取域名
        DomainName = filterContext.HttpContext.Request.Host.Value;

        //获取模块名称
        //  module = filterContext.HttpContext.Request.Url.Segments[1].Replace('/', ' ').Trim();

        //area
        Area = filterContext.RouteData.Values["area"].ToString();

        //获取 controllerName 名称
        ControllerName = filterContext.RouteData.Values["controller"].ToString();

        //获取ACTION 名称
        ActionName = filterContext.RouteData.Values["action"].ToString();

        #endregion 获取链接中的字符
    }

    public int UserId { get; set; }

    /// <summary>
    /// 获取域名
    /// </summary>
    public string DomainName { get; set; }

    /// <summary>
    /// 获取模块名称
    /// </summary>
    public string Area { get; set; }

    /// <summary>
    /// 获取 controllerName 名称
    /// </summary>
    public string ControllerName { get; set; }

    /// <summary>
    /// 获取ACTION 名称
    /// </summary>
    public string ActionName { get; set; }
}